<template>
  <el-row>
    <el-col :span="20">
      <i v-if="row.pid" class="el-icon-s-custom" />
      <span class="company_title">{{ row.name }}</span>
    </el-col>
    <el-col class="company_option" :span="4">
      <span>{{ row.manager }}</span>
      <!-- 下拉菜单            -->
      <el-dropdown>
        <span class="el-dropdown-link">
          操作<i class="el-icon-arrow-down el-icon--right" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item @click.native="$emit('onClickAdd',row)">添加子部门</el-dropdown-item>
          <el-dropdown-item v-if="!isRoot" @click.native="$emit('onClickEdit',row)">查看部门</el-dropdown-item>
          <el-dropdown-item v-if="!isRoot" @click.native="delDept">删除部门</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </el-col>
  </el-row>
</template>

<script>
import { delDeptById } from '@/api/departments'

export default {
  name: 'DeptOptions',
  props: {
    row: {
      type: Object,
      require: true
    },
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {}
  },
  created() {

  },
  methods: {
    // 点击删除的事件
    delDept() {
      this.$confirm(`此操作将永久删除${this.row.name}部门, 是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async() => {
        await delDeptById(this.row.id) // 删除部门
        this.$message.success('删除成功')
        this.$emit('onDel')
      }).catch(() => {
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.el-row {
  width: 100%;

}

.el-icon-s-custom {
  margin-right: 5px;
}

.company_title {
  font-size: 16px;
  font-weight: bold;

}

.company_option {
  display: flex;
  justify-content: flex-end;

  span:nth-child(1) {
    margin-right: 15px;

  }

}
</style>
